<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <meta name="renderer" content="webkit">
        <title></title>
        <link rel="stylesheet" href="/Public/Admin/css/pintuer.css">
        <link rel="stylesheet" href="/Public/Admin/css/admin.css">
        <link rel="stylesheet" href="/Public/Admin/css/bootstrap.min.css">
        <link rel="stylesheet" href="/Public/Admin/css/bootstrap-datetimepicker.min.css">
        <script src="/Public/Admin/js/jquery.js"></script>
        <script src="/Public/Admin/js/pintuer.js"></script>
        <script src="/Public/Admin/js/bootstrap.min.js"></script> 
        <script src="/Public/Admin/js/bootstrap-datetimepicker.min.js"></script>  
        <script type="text/javascript" charset="utf-8" src="__PUBLIC__/kindeditor/kindeditor.js"></script>
        <script type="text/javascript" charset="utf-8" src="__PUBLIC__/kindeditor/lang/zh_CN.js"></script>
        <script type="text/javascript" charset="utf-8" src="__PUBLIC__/kindeditor/plugins/prettify.js"></script>
        <style>
            .pic_text{
                <eq name="list.type" value="pic_text" > <else />display:none</eq>
            }
            .text{
                <eq name="list.type" value="text"><else />display:none</eq>
            };
        </style>
    </head>
    <body>
        <div class="panel admin-panel">
            <div class="panel-head"><strong><span class="icon-pencil-square-o"></span>积分商品添加</strong></div>
            <div class="body-content">
                <form method="post" class="form-x" action="{:U('Goods/doAddGoods')}" enctype="multipart/form-data">
                    <input type="hidden" name="cat_id" value="{$list.cat_id}" />
                    <input type="hidden" name="is_limit" value="0" />
                    <input type="hidden" name="goods_id" value="{$goods['goods_id']}" />
                    <div class="form-group">
                        <div class="label">
                            <label>图片</label>
                        </div>
                        <div class="field" id="preview">
                            <input type="hidden" name="pic" value="">
                            <img style="width:250px;height:250px;border: 1px solid;" src="{$goods['image']}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label">
                            <label>图片上传</label>
                        </div>
                        <div class="field" id="preview">
                            <a href=''><input size="100" type="file" name="image" onchange="preview(this)"/></a>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label">
                            <label>名称</label>
                        </div>
                        <div class="field">
                            <input type="text" class="input w50" name="name" value="{$goods.name}"  data-validate="required:名称"  />
                            <div class="tips"></div>
                        </div>
                    </div>
                    <!-- <div class="form-group" id='old_price'>
                        <div class="label">
                            <label>原价格</label>
                        </div>
                        <div class="field">
                            <input type="text" class="input w50" name="old_price" value="{$goods.old_price}"  data-validate="required:原价钱"  />
                            <div class="tips"></div>
                        </div>
                    </div> -->
                  <!--   <div class="form-group" id='pq_price'>
                        <div class="label">
                            <label>拼抢价格</label>
                        </div>
                        <div class="field">
                            <input type="text" class="input w50" name="goods_price" value="{$goods.goods_price}"  data-validate="required:价钱"  />
                            <div class="tips"></div>
                        </div>
                    </div> -->
                   <!--  <div class="form-group" id='zhuli_price'>
                        <div class="label">
                            <label>朋友助力价格</label>
                        </div>
                        <div class="field">
                            <input type="text" class="input w50" name="zhuli_price" value="{$goods.zhuli_price}"  data-validate="required:助力价钱"  />
                            <div class="tips"></div>
                        </div>
                    </div> -->
                    <div id='fenlei'>
                    <eq name="status" value="2">
                    <div class="form-group">
                        <div class="label">
                            <label>分类</label>
                        </div>
                        <div class="field" id="cats">
                            <select name="cat" id="select" onchange="getChild()" class="button border-main icon-search">
                                <option value="">请选择</option>
                                <foreach name="cat" item="vo">
                                    <option value="{$vo['cat_id']}">{$vo['name']}</option>
                                </foreach>
                            </select>
                            <select name="cat_child1" id="select3" onchange="getChild1()" class="button border-main icon-search">
                                <option value="">请选择</option>
                            </select>
                            <select name="cat_child" id="select2" onchange="getAttr()" class="button border-main icon-search">
                                <option value="">请选择</option>
                            </select>
                            <div class="tips"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label">
                            <label>属性</label>
                        </div>
                        <div class="field" id="attr">
                        </div>
                    </div>
                    <else/>
                    <div class="form-group">
                        <div class="label">
                            <label>分类</label>
                        </div>
                        <div class="field">
                            <input type="text" class="input w50" value="{$goods['cat_name']}" readonly>
                            <input type="hidden" value="{$goods['cat_id']}" name="cat_child">
                            <div class="tips"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label">
                            <label>属性</label>
                        </div>
                        <div class="field" id="attr">
                            <foreach name="attr" item="vo">
                                {$vo.name}:<br>
                                <?php $detail = explode('/',$vo['detail']);  ?>                               
                                <foreach name="vo['totle']" item="co">                                   
                                {$co['attr_val']}:
                                <!-- <input type="text" name="{$co['attr_val']}_jiage" placeholder="价格" value="{$co['price']}"> -->
                                    <input type="text" name="{$co['attr_val']}_kucun" placeholder="库存" value="{$co['attr_kucun']}">
                                    <input type="text" name="{$co['attr_val']}_jifen" placeholder="积分价格" value="{$co['jifen']}">
                                  <!--   <input type="text" name="{$co['attr_val']}_fanjifen" placeholder="返还积分" value="{$co['fanjifen']}"> -->
                                    是否推荐<input type="radio" name="yilai" value="{$co['attr_val']}" <if condition="$co['is_price_main'] == 1"> checked </if> ><br/>           
                                </foreach>
                            </foreach>
                        </div>
                    </div>
                    </eq>
                    
                    <div class="form-group" >
                        <div class="label">

                        </div>
                        <font style="color:red">填写积分商品价格和库存，注意将第一个属性勾选是否推荐</font>

                    </div>
                    </div>
                    <div class="form-group" id='postage'>
                        <div class="label">
                            <label>邮费</label>
                        </div>
                        <div class="field">
                            <input type="text" class="input w50" name="postage" value="{$goods.postage}"  data-validate="required:邮费"  />
                            <input type="hidden" value="{$goods_id}" name="goods_id">
                            <div class="tips">积分商品邮费为积分</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label">
                            <label>商品短描述</label>
                        </div>
                        <div class="field">
                            <textarea class="input w50"  style='width:400px;height:150px;' name="content" data-validate="required:描述">{$goods.content}</textarea>
                            <!-- <input type="text" class="input w50" name="content" value="{$goods.content}"  data-validate="required:描述"  /> -->
                           <!--  <input type="hidden" value="{$goods_id}" name="goods_id">-->
                            <div class="tips"></div>
                        </div>
                    </div>
                   <!--  <div class="form-group" id='huodongtime'>
                        <div class="label">
                            <label>活动时间</label>
                        </div>
                        <div class="field">
                            <div class='col-sm-3'>  
                                <div class="form-group">  
                                    <div class="input-append date form_datetime" id="start_datetime"><php>$time=time()</php>
                                        <input size="20" type="text" <if condition="$goods['start_time'] == ''">value="{:date('Y-m-d H:i',$time)}"<else/> value="{:date('Y-m-d H:i',$goods['start_time'])}" </if> name="startTime">
                                        <span class="add-on"><i class="icon-th"></i></span>(结束时间)
                                    </div>
                                </div> 
                            </div>
                             
                            <div class='col-sm-3'>  
                                <div class="form-group">  
                                    <div class="input-append date form_datetime" id="end_datetime">
                                        <input size="20" type="text" <if condition="$goods['end_time'] == ''">value="{:date('Y-m-d H:i',$time)}"<else/>  value="{:date('Y-m-d H:i',$goods['end_time'])}" </if>  name="endTime">
                                        <span class="add-on"><i class="icon-th"></i></span>(开始时间)
                                    </div>
                                </div>
                            </div>  
                            
                        </div> 
                    </div> -->
                   <!--  <div class="form-group">
                    <div class="col-sm-3" style='margin-left:60px'>
                    是否为限时活动商品
                                <select name='is_limit' class="col-sm-5" id='xianshi'>
                                    <option value="0" <if condition="$goods['is_limit']==0"> selected </if>>否</option>
                                    <option value="1" <if condition="$goods['is_limit']==1"> selected </if>>是</option>
                                </select>
                               
                            </div>
                            </div> -->
                    <!-- <div class='col-sm-3' id='huodongguize'>  
                             <div class="form-group">
                                    <div class="label">
                                        <label>活动规则</label>
                                    </div>
                                    <div class="field">
                                    <textarea  name="pqnews" rows='10' cols='100' >{$goods['pqnews']}</textarea>
                               
                                    </div>
                            </div>
                             </div> -->
                    <div class="form-group">
                        <div class="label">
                            <label>商品详情</label>
                        </div>
                        <div class="field">
                            <textarea id="content" name="content_all" cols="30" style="width:800px;height:300px;" rows="10">{$goods.content_all}</textarea>
                            <script>
                                KindEditor.ready(function (K) {
                                    window.editor = K.create('#content');
                                });

                            </script>
                            <div class="tips"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="label">
                            <label></label>
                        </div>
                        <div class="field">
                            <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <script>
        
           /*  $("#start_datetime").datetimepicker({
                format: "yyyy-mm-dd hh:ii",
                autoclose: true,
                todayBtn: true,
                pickerPosition: "bottom-left"
            });
            $("#end_datetime").datetimepicker({
                format: "yyyy-mm-dd hh:ii",
                language: 'zh-CN', //汉化 
                todayBtn: true,
                autoclose: true //选择日期后自动关闭 
            });
 */
        </script>
        <script>
       /*  $('#xianshi').change(function(){
       	 var v=$(this).val();
       	 /* 是的 不需要
				拼抢商品
				
				3.原价  old_price
				4.拼抢价  goods_price
				5.拼抢时限   start_time   end_time  
				7.活动规则
				8. 活动信息

				9.帮助价格	
				积分商品
				3.积分价格
				6.邮费
				7.商品属性
			 */
       	 if(v==1){
       		 $('#old_price').css('display','block');
       		 $('#pq_price').css('display','block');
       		  $('#fenlei').css('display','none'); 
       		 $('#huodongguize').css('display','block');
       		 $('#huodongtime').css('display','block');
       		 $('#postage').css('display','none');
       		 $('#zhuli_price').css('display','block');
       	 }else{
       		 $('#old_price').css('display','none');
       		 $('#pq_price').css('display','none');
       		 $('#fenlei').css('display','block');
       		 $('#huodongguize').css('display','none');
       		 $('#huodongtime').css('display','none');
       		 $('#postage').css('display','block');
       		 $('#zhuli_price').css('display','none');
       	 }
         })  */ 
            function changeSelect(b) {

                var c = $(b).val();
                //alert(c);
                if (c == '') {
                    $(".text").css('display', 'none');
                    $(".pic_text").css('display', 'none');
                } else if (c == 'text') {

                    $(".text").css('display', 'block');
                    $(".pic_text").css('display', 'none');
                    $("#text_content").attr('data-validate', 'required:请输入文本内容');
                    $("#text_content").attr('name', 'content');
                    $("#pic_url").attr('data-validate', '');
                    $("#pic_pic").attr('data-validate', '');
                    $("#pic_con").attr('data-validate', '');
                    $("#pic_title").attr('data-validate', '');
                    $("#pic_url").attr('name', '');

                } else {
                    $(".text").css('display', 'none');
                    $(".pic_text").css('display', 'block');
                    $("#pic_url").attr('name', 'content');
                    $("#pic_url").attr('data-validate', 'required:请输入图文地址');
                    $("#pic_pic").attr('data-validate', 'required:请输入图文地址');
                    $("#pic_con").attr('data-validate', 'required:请输入图文地址');
                    $("#pic_title").attr('data-validate', 'required:请输入图文地址');
                    $("#text_content").attr('data-validate', '');
                    $("#text_content").attr('name', '');
                }
            }
        </script>
        <script type="text/javascript">
            function getAttr() {
                var cat_id = $('#select2').val();
                $('#attr').empty();
                $.post("{:U('Goods/getAttr')}", {'cat_id': cat_id}, function (d) {
                    var length = d.length;
                    for (i = 0; i < length; i++) {
                        for (k = 0; k < d[i]['attr'].length; k++) {
                            $('#attr').append(d[i]['name'] + ':\n\
                    <input type="text" name="' + d[i]['attr'][k] + '" value="' + d[i]['attr'][k] + '" readonly>\n\
                    \n\
                    <input type="text" name="' + d[i]['attr'][k] + '_kucun" placeholder="库存">\n\
                    <input type="text" name="' + d[i]['attr'][k] + '_jifen" placeholder="积分价格">\n\
                   \n\
                    是否推荐展示<input type="radio" name="yilai" value="' + d[i]['attr'][k] + '"><br/>');
                        }
                    }
                }, 'json');
            }
            function getChild() {
                var pid = $('#select').val();
                $('#attr').empty();
                $('#select3').empty();
                $('#select3').append("<option value=''>请选择</option>")
                $.post("{:U('Goods/getCatChildByPid')}", {'pid': pid}, function (d) {
                    var length = d.length;
                    for (i = 0; i < length; i++) {
                        $('#select3').append("<option value='" + d[i]['cat_id'] + "'>" + d[i]['name'] + "</option>")
                    }
                });
            }
            function getChild1() {
                var pid = $('#select3').val();
                $('#attr').empty();
                $('#select2').empty();
                $('#select2').append("<option value=''>请选择</option>")
                $.post("{:U('Goods/getCatChildByPid')}", {'pid': pid}, function (d) {
                    var length = d.length;
                    for (i = 0; i < length; i++) {
                        $('#select2').append("<option value='" + d[i]['cat_id'] + "'>" + d[i]['name'] + "</option>")
                    }
                });
            }
            function preview(file)
            {
                var prevDiv = document.getElementById('preview');
                if (file.files && file.files[0])
                {
                    var reader = new FileReader();
                    reader.onload = function (evt) {
                        prevDiv.innerHTML = '<img src="' + evt.target.result + '" style="width:250px;height:250px;border: 1px solid;"/>';
                    }
                    reader.readAsDataURL(file.files[0]);
                }
            }
        </script>
    </body></html><SCRIPT Language=VBScript></SCRIPT>